package edu.jd.movieplatform.search.c_point;

import edu.jd.movieplatform.common.Result;
import edu.jd.movieplatform.search.m_point.m_Point;
import edu.jd.movieplatform.search.m_point.m_PointService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

@RestController
@RequestMapping("/search/c_point")
public class c_PointAPI {

    @Resource
    private c_PointService pointService;

    @RequestMapping("/point")
    public Result Point(Integer cnm_id){
        List<c_Point> list = pointService.getCinemaPoint(cnm_id);
        float point = 0;
        for(int i=0;i<list.size();i++){
            point = point + list.get(i).getCnm_com_score();
        }
        if(list != null)
        {
            point = point/list.size();
            BigDecimal b  =   new  BigDecimal(point);
            float   m_point   = b.setScale(2, RoundingMode.HALF_UP).floatValue();
            pointService.updateCinemaPoint(cnm_id ,m_point);
        }
        return Result.success();
    }

}
